#include "DefaultState.hpp"
#include "../Notification.hpp"
#include <TweenEngine/Tween.h>
#include <cpp3ds/System/I18n.hpp>
#include <cpp3ds/Window/Window.hpp>

namespace Template {

DefaultState *g_defaultState = nullptr;

DefaultState::DefaultState(StateStack& stack, Context& context, StateCallback callback)
: State(stack, context, callback)
{

	g_defaultState = this;

	m_bannerImage.loadFromFile("images/banner.png");
	m_bannerSprite.setTexture(m_bannerImage, true);
	m_bannerSprite.setPosition(200.f, 120.f);
	m_bannerSprite.setOrigin(m_bannerSprite.getLocalBounds().width / 2, m_bannerSprite.getLocalBounds().height / 2);


	m_noticeText.setFillColor(cpp3ds::Color::Black);
	m_noticeText.setString(" Hello, freeShop Team here!\n\n We are sad to announce this, but the freeShop\n application is no longer working, aka. at the end of it's\n lifetime (EOL). This was caused by recent security\n changed in the Nintendo servers (CDNs), which\n freeShop needs to work.\n This can NOT be fixed using any legal method!\n - But one good thing: Pressing the Start button won't\n crash the app anymore! yay!\n\n Thank you all for using freeShop!\n\n You may now want to uninstall the application.\n Press Start to exit.\n ");
	m_noticeText.setCharacterSize(11);
	m_noticeText.setPosition(6.f, 6.f);
	m_noticeText.useSystemFont();

	m_importantText.setFillColor(cpp3ds::Color::Red);
	m_importantText.setString("Important Information");
	m_importantText.setCharacterSize(20);
	m_importantText.setPosition(90.f, 180.f);
	m_importantText.useSystemFont();
}

DefaultState::~DefaultState()
{

}

void DefaultState::renderTopScreen(cpp3ds::Window& window)
{
	window.draw(m_bannerSprite);
	window.draw(m_importantText);
}

void DefaultState::renderBottomScreen(cpp3ds::Window& window)
{
	window.draw(m_noticeText);	
}

bool DefaultState::update(float delta)
{
	m_tweenManager.update(delta);

	return true;
}

bool DefaultState::processEvent(const cpp3ds::Event& event)
{
	if (event.type == cpp3ds::Event::KeyPressed) {
		switch (event.key.code) {
			case cpp3ds::Keyboard::Start: {
				requestStackClear();
				return true;
			}
		}
	}
	return true;
}

} // namespace Template
